home *** CD-ROM | disk | FTP | other *** search
- Path: qualcomm.com!not-for-mail
- From: drew@qualcomm.com (Drew Eckhardt)
- Newsgroups: comp.lang.c++
- Subject: Re: Structure names are pointers? Writing to them?
- Date: 15 Mar 1996 23:55:52 -0700
- Organization: QUALCOMM, Incorporated; Boulder, CO, USA
- Message-ID: <4idolo$g92@qualcomm.com>
- References: <4idmdo$2b2@news.voicenet.com>
- NNTP-Posting-Host: littlebear.qualcomm.com
-
- In article <4idmdo$2b2@news.voicenet.com>, <deaton@cygnus.rsabbs.com> wrote:
- >blahS blah[15]; fwrite(blah,sizeof(blah),1,fptr);
-
- works, as expected.
-
- >blahS blah; fwrite(blah,sizeof(blah),1,fptr);
- >my compiler spits out an error.
-
- Be happy you're using a C++ compiler which flags this as a fatal error,
- rather than a 'C' compiler which may result in runtime nasal demons.
-
- >As far as I understood, structure names acted the same way as array names:
-
- In both 'C' and C++, a conversion between an array and a pointer to the base
- type exists, meaning an array name in a pointer context evaluates to
- &array[0].
-
- However, no conversion exists for structures, and would be undesirable
- in C++ since it would preclude (or introduce some less intuitive syntax for)
- passing objects by value.
-
- >they are pointers.
-
- They are not pointers; there is merely a conversion which allows them
- to act as pointers in certain useful places. Thinking of them as pointers
- will get you in trouble. For instance, you may try to use &array where
- &pointer is required or vice versa.
-
- >So why isn't this working?
-
- As noted, no such conversion exists for structures. You want to use
- this instead:
-
- fwrite (&blah, sizeof(blah), 1, fptr)
-
-
- --
- Four boxes : soap, ballot, jury, ammo. | Work: drew@Qualcomm.COM
- Use in that order. | Play: drew@PoohSticks.ORG
-